package com.ruoyi.ems.controller;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ems.domain.RefundOrder;
import com.ruoyi.ems.service.IRefundOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 退款单Controller
 * 
 * @author sh
 * @date 2023-12-11
 */
@Anonymous
@RestController
@RequestMapping("/ems/refundOrder")
public class RefundOrderController extends BaseController
{
    @Autowired
    private IRefundOrderService refundOrderService;

    /**
     * 查询退款单列表
     */
//    @PreAuthorize("@ss.hasPermi('ems:refundOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(RefundOrder refundOrder)
    {
        startPage();
        List<RefundOrder> list = refundOrderService.selectRefundOrderList(refundOrder);
        return getDataTable(list);
    }

    /**
     * 导出退款单列表
     */
//    @PreAuthorize("@ss.hasPermi('ems:refundOrder:export')")
    @Log(title = "退款单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RefundOrder refundOrder)
    {
        List<RefundOrder> list = refundOrderService.selectRefundOrderList(refundOrder);
        ExcelUtil<RefundOrder> util = new ExcelUtil<RefundOrder>(RefundOrder.class);
        util.exportExcel(response, list, "退款单数据");
    }

    /**
     * 获取退款单详细信息
     */
//    @PreAuthorize("@ss.hasPermi('ems:refundOrder:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(refundOrderService.selectRefundOrderById(id));
    }

    /**
     * 新增退款单
     */
//    @PreAuthorize("@ss.hasPermi('ems:refundOrder:add')")
    @Log(title = "退款单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RefundOrder refundOrder)
    {
        return toAjax(refundOrderService.insertRefundOrder(refundOrder));
    }

    /**
     * 修改退款单
     */
//    @PreAuthorize("@ss.hasPermi('ems:refundOrder:edit')")
    @Log(title = "退款单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RefundOrder refundOrder)
    {
        return toAjax(refundOrderService.updateRefundOrder(refundOrder));
    }

    /**
     * 删除退款单
     */
//    @PreAuthorize("@ss.hasPermi('ems:refundOrder:remove')")
    @Log(title = "退款单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(refundOrderService.deleteRefundOrderByIds(ids));
    }
}
